var express = require('express');
var router = express.Router();

// 自定义模块
const query = require('../../utils/mysql');
const Result = require('../../utils/api');

var checkAuth = require('../../utils/checkAuth')

// 后台评论列表
router.post('/comment/list', checkAuth, async function (req, res, next) {
    try {
        let params = req.body

        let sql = "select c.id,u.avatar,u.nickname,u.website,u.email,c.`comment`,a.article_title,c.aid,c.add_time from blog_comment as c left join blog_user as u on c.uid=u.id  LEFT JOIN blog_article as a on c.aid = a.id ORDER BY c.add_time DESC limit ?,?"
        let sqlArr = [(params.page - 1) * params.limit, params.limit]
        let data = await query(sql, sqlArr)
        let countsql = "SELECT COUNT(0) as count FROM blog_comment"
        let [{ count }] = await query(countsql)
        Result.success(res, { data: Array.from(data), count: count })
    } catch (error) {
        Result.fail("error")
    }
})


module.exports = router;